package com.fragment;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import model.LTServiceModel;
import model.PeopleModel;
import model.SearchModel;
import model.ServiceModel;

import org.xutils.x;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import com.dialog.LTDialog;
import com.friehome.app.R;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.net.HttpRequestUtil;
import com.net.HttpResponse;
import com.net.TTHttpRequestControll;

import adapter.MainAdapter;
import adapter.SearchAdapter;
import android.app.DatePickerDialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.DatePicker;
import android.widget.ListView;
import android.widget.TextView;

public class Fragment4 extends BaseFragment{
	
	@ViewInject(R.id.text1)
	TextView text1;
	@ViewInject(R.id.text2)
	TextView text2;
	@ViewInject(R.id.text3)
	TextView text3;
	@ViewInject(R.id.text4)
	TextView text4;
	@ViewInject(R.id.text5)
	TextView text5;
	@ViewInject(R.id.text6)
	TextView text6;
	@ViewInject(R.id.text7)
	TextView text7;
	@ViewInject(R.id.text8)
	TextView text8;
	@ViewInject(R.id.text9)
	TextView text9;
	
	String id;
	List<TextView> views = new ArrayList<TextView>();
	List<ServiceModel> data = new ArrayList<ServiceModel>();
	
	String[] texts = new String[]{"遗体接收","业务洽谈","手续办理","缴费结算","遗体入殓","告别服务","火化服务","骨灰领取","服务结束"};
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment4, null);
		x.view().inject(this, view);
		
		id = getArguments().getString("id");
		
		views.add(text1);
		views.add(text2);
		views.add(text3);
		views.add(text4);
		views.add(text5);
		views.add(text6);
		views.add(text7);
		views.add(text8);
		views.add(text9);
		
		
		getData();
		
		return view;
	}
	
	public void initData(){
		for (int i = 0 ;i < texts.length;i++) {
			String text = texts[i];
			int color = R.color.service_1;
			a: for (ServiceModel m : data) {
				if (m.name.equals(text)) {
					if (m.use.equals("0")) {
						if (m.complete.equals("0")) {
							color = R.color.service_2;
						}else{
							color = R.color.service_3;
						}
					}
					break a;
				}
			}
			views.get(i).setText(text);
			views.get(i).setTextColor(getResources().getColor(color));
		}
	}
	
	public void getData(){
		TTHttpRequestControll.httpService(getActivity(),id, new HttpRequestUtil.HttpRonspontCallBack() {
			
			@Override
			public void callBack(HttpResponse result) {
				try {
					if (result.success) {
					//	JSONObject ob=  new JSONObject(result.content);
						data = new Gson().fromJson(result.content, new  TypeToken<List<ServiceModel>>(){}.getType() );
				
						initData();
					}else{
						toast(result.errorMsg);
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				
					
				
			}
		});
	}
}
